package com.imay.live.activity.family.helper.session.extension;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.imay.live.helper.UrlHelper;

/**
 * Created by nick on 2017/9/14.
 * 自定义消息_动态
 */

public class DynamicsAttachment extends CustomAttachment {

    private final String KEY_FEEDID = "feedId";
    private final String KEY_FEEDTYPE = "feedType";
    private final String KEY_IMGURL = "imgUrl";
    private final String KEY_MSG = "msg";
    private final String KEY_VIDEOURL = "videoUrl";

    private long feedId;
    private int feedType;
    private String imgUrl;
    private String msg;
    private String videoUrl;

    DynamicsAttachment() {
        super(CustomAttachmentType.dynamics);
    }

    @Override
    protected void parseData(JSONObject data) {
        feedId = data.getLong(KEY_FEEDID);
        feedType = data.getInteger(KEY_FEEDTYPE);
        imgUrl = data.getString(KEY_IMGURL);
        msg = data.getString(KEY_MSG);
        videoUrl = data.getString(KEY_VIDEOURL);
    }

    @Override
    protected JSONObject packData() {
        JSONObject data = new JSONObject();
        data.put(KEY_FEEDID, feedId);
        data.put(KEY_FEEDTYPE, feedType);
        data.put(KEY_IMGURL, imgUrl);
        data.put(KEY_MSG, msg);
        data.put(KEY_VIDEOURL, videoUrl);
        return data;
    }

    public long getFeedId() {
        return feedId;
    }

    public int getFeedType() {
        return feedType;
    }

    public String getImgUrl() {
        return imgUrl;
    }

    public String getMsg() {
        return msg;
    }

    public String getVideoUrl() {
        return videoUrl;
    }

    public String getUrl() {
        return isImage() ? imgUrl : UrlHelper.getVideoThumbUrl(videoUrl);
    }

    public boolean isImage() {
        return 1 == feedType;
    }
}
